package cn.it.shop.util;

import java.io.IOException;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;
import org.springframework.stereotype.Component;

import cn.it.shop.service.SendMessageUtil;

@Component("sendMessageUtil")
public class SendMessageUtilImpl implements SendMessageUtil {

	@Override
	public int sendMessage(String number, int id) {
		// 1: 打开浏览器
		HttpClient client = new HttpClient();
		// 2: post请求,设置请求行信息,和请求的参数(如果有)
		PostMethod postMethod = new PostMethod("http://utf8.sms.webchinese.cn");
		postMethod.setRequestHeader("Content-Type",
				"application/x-www-form-urlencoded;charset=UTF-8");
		postMethod.setParameter("Uid", "java_0821");
		postMethod.setParameter("Key", "c113da4878e781b6db18");
		postMethod.setParameter("smsMob", number);
		postMethod.setParameter("smsText", "订单" + id + "已经支付成功");
		// 3: 发送请求
		try {
			return client.executeMethod(postMethod);
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}
}
